<template>
  <div class="search-main">
    <el-dialog
      title="Search"
      :visible.sync="dialogVisible"
      width="55%"
      :before-close="handleClose"
    >
      <!-- 关键字 -->
      <div class="keyword">
        <el-input
          v-model="keyword"
          placeholder="输入关键字...."
          @input="getActiveList"
          @keydown.native="getArticleList"
        ></el-input>
      </div>
      <!-- 查询列表 -->
      <div class="serach-list" v-if="articleList.length != 0">
        <ul>
          <li v-for="item in articleList" :key="item.articleId">
            <router-link
              :to="{
                path: '/articleDetail',
                query: { articleId: item.articleId },
              }"
              :key="item.articleId"
            >
              <!-- 标题 -->
              <div class="search-header">
                <h2>{{ item.articleTitle }}</h2>
              </div>
              <!-- 描述 -->
              <div class="search-des">
                <span>
                  {{ item.articleSummary }}
                </span>
              </div>
            </router-link>
          </li>
        </ul>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { getArticleListByKeyword } from "@/api/index";
export default {
  components: {},
  name: "search",
  props: ["dialogVisible"],
  data() {
    return {
      keyword: "",
      articleList: [],
    };
  },
  created() {},
  // 创建一个过滤器
  filters: {},
  methods: {
    handleClose(done) {
      this.$confirm("确认关闭？")
        .then((_) => {
          // 将数据传输给父亲
          this.$emit("closeDialog");
        })
        .catch((_) => {});
    },
    getArticleList() {
      // 模糊查询
      getArticleListByKeyword({ keyword: this.keyword }).then((resp) => {
        console.log(resp);
        this.articleList = resp.data;
      });
    },
  },
};
</script>

<style scoped>
.search-main {
  margin: 80px auto;
}
.el-dialog__title {
  margin-left: 45% !important;
}

.el-dialog__header {
  border-bottom: 1px solid #c7c3bd;
}
.el-input__inner {
  border: none;
  border-bottom: 2px solid #149898;
}

.serach-list ul li {
  width: 80%;
  margin: 0 auto;
}

.search-header {
  width: 100%;
  height: 50px;
  border-left: 2px solid rgb(3, 91, 146);
}

.search-des {
  width: 100%;
  overflow: hidden;
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
}
</style>
